package org.flexspeedup.blog.views
{
import org.flexspeedup.blog.controllers.IBlogController;

import spark.components.supportClasses.SkinnableComponent;

/**
 * Renders blog posts
 */
public class Blog extends SkinnableComponent
{
    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new <code>Blog</code> instance.
     */
    public function Blog()
    {
        super();
    }
    
    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    //----------------------------------
    //  blogController
    //----------------------------------
    /**
     *  @private
     */    
    private var _blogController:IBlogController;
    
    [Bindable]
    /**
     * 
     */
    public function get blogController():IBlogController
    {
        return _blogController;
    }
    
    [Inject(source="blogController")]
    public function set blogController(value:IBlogController):void
    {
        if (value == _blogController || !value)
            return;
        
        _blogController = value;
    }

    //----------------------------------
    // defaultCategory
    //----------------------------------
    [Bindable]
    /**
     * String to use as a default category .
     */
    public var defaultCategory:String;
   
    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------
    
    //----------------------------------
    //  getPosts
    //----------------------------------
    /**
     * Retrieves a page of posts from the database
     */
    public function getPosts(page:int = 1, pageSize:int = 10, category:String = null):void
    {
        blogController.getPosts(page, pageSize, category || defaultCategory);
    }     
}
}